package org.hawk.gwtppc.webtest.tests.classsuite;

import java.lang.reflect.Modifier;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.ClassMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;

public class GetDeclaredFieldTest implements Test {

	public void run() throws Throwable {
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("serialVersionUID").getName(), "serialVersionUID");
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("serialVersionUID").getModifiers(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("serialVersionUID").getType(), long.class);
		
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("staticString").getName(), "staticString");
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("staticString").getModifiers(), Modifier.PRIVATE | Modifier.STATIC);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("staticString").getType(), String.class);
		
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("parent").getName(), "parent");
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("parent").getModifiers(), Modifier.PROTECTED);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("parent").getType(), ClassMock.class);
		
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("flag").getName(), "flag");
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("flag").getModifiers(), Modifier.PUBLIC);
		Asserts.assertEquals(SubClassMock1.class.getDeclaredField("flag").getType(), boolean.class);
		
		try {
			SubClassMock1.class.getDeclaredField("blablabla");
			Asserts.fail();
		} catch (NoSuchFieldException ex) {
		}
		try {
			SubClassMock1.class.getDeclaredField("switcher");
			Asserts.fail();
		} catch (NoSuchFieldException ex) {
			
		}
	}

	public String getName() {
		return "getDeclaredField(String)";
	}

}
